package com.shwread.android.ui.dialog;

import android.view.LayoutInflater;
import android.view.View;
import android.widget.TextView;

import com.shwread.android.qysw.activity.MainActivity;
import com.shwread.android.qysw10000182.R;

import java.io.File;
import java.io.IOException;

import logic.util.FileUtil;
import logic.util.SDcardUtil;
import logic.util.Util;

public class ClearCacheDialog extends CommonDialog

{
	protected TextView tvText;
	protected TextView tvOk;
	protected View vDivider;
	protected View vCancel;

	private MainActivity context;
	protected TextView vTitle;
	private File diskCachePath;
	//private TextView tvClearCache;
	
	public ClearCacheDialog(MainActivity context) {
		super(context);
		
		this.context = context;	
		
		setCanceledOnTouchOutside(true);		
		findViews();
		setListeners();
	}
	
	private void findViews() {
		View view = LayoutInflater.from(context).inflate(R.layout.common_dialog, null);

		tvText = (TextView) view.findViewById(R.id.common_dialog_text);
		tvText.setText("确认清除缓存吗？");
		tvOk = (TextView) view.findViewById(R.id.common_dialog_ok);
		vDivider = view.findViewById(R.id.common_dialog_divider);
		vCancel = view.findViewById(R.id.common_dialog_cancel);
		vTitle=(TextView)view.findViewById(R.id.common_dialog_title);
		//tvClearCache = (TextView) findViewById(R.id.user_info_setting_clear_cache_tv);
		
		setContentView(view);
	}
	
	private void setListeners() {
		ClickListener l = new ClickListener();

		tvOk.setOnClickListener(l);
		vCancel.setOnClickListener(l);
	}
	
	protected void clickOk(View v) {
		 diskCachePath = SDcardUtil.getImagePath();
			try
         {
             FileUtil.deleteFolderFile(diskCachePath.getPath(), false);
             Util.showToast(context, "清除缓存成功！");
             context.getUIHandler().sendEmptyMessage(123);
             dismiss();
            // tvClearCache.setText("0M");   
         }
         catch (IOException e)
         {
             e.printStackTrace();
           dismiss();
         }
		}


	protected void clickCancel(View v) {
		dismiss();
	}

	private class ClickListener implements View.OnClickListener {

		@Override
		public void onClick(View v) {
			switch(v.getId()) {
			case R.id.common_dialog_ok:
				clickOk(v);
				break;
			case R.id.common_dialog_cancel:
				clickCancel(v);
				break;
			}
		}
		
	}
	
	
	
}
